<template>
    <div class="app-container">
        <div class="search-container">
            <el-form ref="queryParamsRef" :inline="true" :model="queryParams" label-width="100px">
                <el-form-item label="患者姓名" prop="name">
                    <el-input
                        v-model="queryParams.name"
                        clearable
                        placeholder="请输入患者姓名"
                        @keyup.enter="handleQuery"
                    />
                </el-form-item>
                <el-form-item label="住院号" prop="hospitalNo">
                    <el-input
                        v-model="queryParams.hospitalNo"
                        clearable
                        placeholder="请输入住院号"
                        @keyup.enter="handleQuery"
                    />
                </el-form-item>
                <el-form-item>
                    <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery"/>
                </el-form-item>
            </el-form>
        </div>
        <el-table v-adaptive="280" :border="true" :data="patientInfoList"
                  :header-cell-style="$headerCellStyle"
                  :stripe="true">
            <el-table-column :align="'left'"
                             :header-align="'center'" fixed="left" label="患者信息" prop="name" width="140">
                <template #default="scope">
                    {{ scope.row.name }}
                    <span style="margin-left: -10px">
                            <svg-icon :icon-class="dictStore.getMateDictInfo(
                                dictDataMap['sys_user_sex'],
                                scope.row.sex
                            ).dictValue === '1'
                                ? 'man'
                                : 'woman'
                                " style="margin-left: 10px"/>
                        </span>
                    {{ scope.row.age }} 岁{{ scope.row.ageMonth }} 月
                    <!-- {{ scope.row.ageDay }}天 -->
                </template>
            </el-table-column>
            <el-table-column :align="'center'" fixed="left" label="住院号" prop="hospitalNo" width="130">
                <template #default="scope">
                    <span class="ys-css">{{ scope.row.hospitalNo }}</span>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="电话" prop="phone" width="100"/>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="身份证号" prop="idNo" width="140"/>
            <el-table-column :align="'center'" label="费别" prop="chargeType" width="90">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['medical_insurance_type']" :value="scope.row.chargeType"/>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="入院时间" prop="admissionTime" width="130">
                <template #default="scope">
                    <span>{{ $parseTime(scope.row.admissionTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="是否结算" prop="settledIndicator" width="80">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['sys_yes_no']" :value="scope.row.settledIndicator"/>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="出院时间" prop="dischargeTime" width="130">
                <template #default="scope">
                    <span>{{ $parseTime(scope.row.dischargeTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="出院科室" prop="deptDischargeToName" width="100"/>
            <el-table-column :align="'center'" label="出院病区" prop="wardDischargeToName" width="100"/>
            <el-table-column :align="'center'" label="出院方式" prop="settledType" width="100"/>
            <el-table-column :align="'center'" label="预交金" prop="patPrepaymentSum" width="120">
                <template #default="scope">
                    <span class="ys-css">{{
                            scope.row.patPrepaymentSum
                                ? scope.row.patPrepaymentSum : 0.00
                        }}</span>元
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="总费用" prop="costs" width="120">
                <template #default="scope">
                    <span class="ys-css">{{
                            scope.row.costs
                                ? scope.row.costs : 0.00
                        }}</span>元
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="预交金余额" prop="patPrepaymentSumBalance" width="120">
                <template #default="scope">
                    <span class="ret-ys-css">{{
                            (Number(scope.row.patPrepaymentSum) - Number(scope.row.costs)).toFixed(2)
                        }}</span>元
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="管床医生" prop="doctorInChargeName" width="120"/>
            <el-table-column :align="'center'" label="责任护士" prop="dutyNurseName" width="120"/>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="入院诊断" prop="diagnosis"
                             width="130"/>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="出院诊断" prop="leaveDiagnosis"
                             width="130"/>
            <el-table-column :align="'center'" label="患者所在科室" prop="deptStayedName" width="100"/>
            <el-table-column :align="'center'" label="患者所在病区" prop="wardCodeName" width="100"/>
            <el-table-column :align="'center'" label="联系人" prop="contacts" width="100"/>
            <el-table-column :align="'center'" label="联系人电话" prop="contactsPhone" width="100"/>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="联系人地址" prop="contactsAddress"
                             width="130"/>
        </el-table>
        <pagination
            v-show="total>0"
            v-model:limit="queryParams.pageSize"
            v-model:page="queryParams.pageNum"
            :total="total"
            @pagination="getList"
        />
    </div>
</template>

<script lang="ts" setup>

import {useUserStoreHook} from "@/store/modules/user.ts";
import {useDictStoreHook} from "@/store/modules/dict.ts";
import {leaveHospitalPatientList} from "@/api/hospitalization/patVisit.ts"

const dictStore = useDictStoreHook();

const useUserStore = useUserStoreHook();
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo;
const {proxy} = getCurrentInstance() as any;
const currentSelectDept = proxy.$currentSelectDept

let dictDataMap = ref(dictStore.isTypeGetData('medical_insurance_type', 'sys_user_sex', 'sys_yes_no'
))
const total = ref(0);
const queryParams = ref<any>({
    orgId: userInfo.orgId,
    pageNum: 1,
    pageSize: 10,
    inFlag: "2",
    // 出院时间是否为空 0是 1否
    isDischargeTime: 1
})
const patientInfoList = ref<any>([])


function handleQuery() {
    getList()
}

function resetQuery() {
    queryParams.value.name = ""
    queryParams.value.hospitalNo = ""
    getList()
}

function getList() {
    leaveHospitalPatientList(queryParams.value).then((res: resType) => {
        patientInfoList.value = res.rows
        patientInfoList.value.forEach((item: any) => {
            let thisPatPrepaymentSum: number = 0
            if (item.patPrepaymentVos) {
                item.patPrepaymentVos.forEach((patPrepayment: any) => {
                    thisPatPrepaymentSum += Number(patPrepayment.amountOfMoney)
                })
            }
            item.patPrepaymentSum = thisPatPrepaymentSum.toFixed(2)
            let thisCosts: number = 0
            if (item.InpBillDetailVos) {
                item.InpBillDetailVos.forEach((patPrepayment: any) => {
                    thisCosts += Number(patPrepayment.costs)
                })
            }
            item.costs = thisCosts.toFixed(2)
        })
        total.value = res.total
    })
}

defineExpose({
    getList
})

</script>


<style scoped>

</style>
